<template>
  <div>
    <tableComponents
      :isHavePagination="false"
      :isShow="false"
      :isHaveExport="false"
      @toAdd="showAdd"
      :isShowBottom='false'
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list"
          v-loading="loading"
          header-row-class-name="head_color"
          stripe
          tooltip-effect="dark"
          style="width: 99.9%"
        >
          <el-table-column label="打印机编号" min-width="130">
            <template slot-scope="scope" style="vertical-align: text-top;">{{scope.row.sn}}</template>
          </el-table-column>

          <el-table-column label="备注名称" min-width="80">
            <template slot-scope="scope" style="vertical-align: text-top;">{{scope.row.remarks}}</template>
          </el-table-column>

          <el-table-column label="操作" min-width="100">
            <template slot-scope="scope">
              <el-button
                :loading="$store.state.isLoading"
                size="mini"
                @click="del(scope.row.id)"
                type="primary"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      title="添加"
      :append-to-body="true"
      @close="show = false"
      :visible.sync="show"
      width="800px"
    >
      <el-form :model="printObj" label-width="160px">
        <el-form-item label="打印机编号(必填)" prop="pid_name">
          <el-col :span="12">
            <el-input v-model="printObj.sn" size="small"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="打印机识别码(必填)" prop="title">
          <el-col :span="12">
            <el-input v-model="printObj.key" size="small"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="备注名称" prop="title">
          <el-col :span="12">
            <el-input v-model="printObj.remarks" size="small"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="save">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
export default {
  data() {
    return {
      loading: false,
      list: [],
      show: false,
      printObj: {
        sn: "",
        key: "",
        remarks: ""
      }
    };
  },
  components: {
    HeadTitle
  },
  methods: {
    showAdd() {
      this.printObj = { sn: "", key: "", remarks: "" };
      this.show = true;
    },
    del(id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getShops.printer_del({ id: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.get_data();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    get_data() {
      this.loading = true;
      this.$api.getShops.printer_lists_all({}).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    save() {
      this.$api.getShops.printer_saveadd(this.printObj).then(res => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "", "success");
          this.show = false;
          this.get_data();
        } else {
          this.$swal("添加失败！", res.data.result, "error");
        }
      });
    }
  },
  created() {
    this.get_data();
  },
  computed: {}
};
</script>

<style lang="less" scoped>
</style>
